
set(OGR_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogr)
set(OGR_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/ogr)
include_directories(${OGR_CURRENT_SOURCE_DIR})
include_directories(${OGR_CURRENT_BINARY_DIR})
include_directories(${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts)

add_definitions(-DOGR_ENABLED)

# needed packages
find_package(EXPAT REQUIRED)
if(EXPAT_FOUND)
    include_directories(${EXPAT_INCLUDE_DIRS})
    add_definitions(-DHAVE_EXPAT)
endif(EXPAT_FOUND)

find_package(GEOS REQUIRED)
if(GEOS_FOUND)
    #get GEOS root directory from GEOS_INCLUDE_DIR
    get_filename_component(GEOS_ROOT ${GEOS_INCLUDE_DIR} PATH)
    include_directories(${GEOS_INCLUDE_DIR})
    include_directories(${GEOS_ROOT}/capi)
    add_definitions(-DHAVE_GEOS)
endif(GEOS_FOUND)

find_package(PROJ REQUIRED)
if(PROJ_FOUND)
    include_directories(${PROJ_INCLUDE_DIR})
    add_definitions(-DHAVE_PROJ -DPROJ_STATIC)
endif(PROJ_FOUND)

add_definitions(-DUSE_CPL)
#add_definitions(-D_UNICODE)

option(OGR_CSV "Build csv driver" YES)
option(OGR_DXF "Build dxf driver" YES)
option(OGR_GML "Build gml driver" YES)
option(OGR_KML "Build kml driver" YES)
option(OGR_LIBKML "Build libkml driver" YES)
option(OGR_TAB "Build MapInfo driver" YES)
option(OGR_PG "Build PostGIS driver" YES)
option(OGR_SHP "Build Shape driver" YES)
option(OGR_VRT "Build vrt driver" YES)
option(OGR_MEM "Build mem driver" YES)
option(OGR_JSON "Build geojson driver" YES)

set(OGR_HHEADERS
    ${OGR_CURRENT_SOURCE_DIR}/ogrgeomediageometry.h
    ${OGR_CURRENT_SOURCE_DIR}/ogrpgeogeometry.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_api.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_core.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_expat.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_feature.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_featurestyle.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_geometry.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_geos.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_p.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_spatialref.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_api.h
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_esri_names.h
    ${OGR_CURRENT_SOURCE_DIR}/swq.h
)

set(OGR_CSOURCES
    ${OGR_CURRENT_SOURCE_DIR}/gml2ogrgeometry.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr2gmlgeometry.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ograssemblepolygon.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrct.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrcurve.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrfeature.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrfeaturedefn.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrfeaturequery.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrfeaturestyle.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrfielddefn.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrgeomediageometry.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrgeometry.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrgeometrycollection.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrgeometryfactory.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrlinearring.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrlinestring.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrmultilinestring.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrmultipoint.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrmultipolygon.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrpgeogeometry.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrpoint.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrpolygon.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrspatialreference.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogrsurface.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogrutils.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_api.cpp 
    #ogr_capi_test.c 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_expat.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_fromepsg.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_opt.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srsnode.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_dict.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_erm.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_esri.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_ozi.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_panorama.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_pci.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_proj4.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_usgs.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_validate.cpp
    ${OGR_CURRENT_SOURCE_DIR}/ogr_srs_xml.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/swq.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/swq_expr_node.cpp 
    ${OGR_CURRENT_SOURCE_DIR}/swq_op_general.cpp
    ${OGR_CURRENT_SOURCE_DIR}/swq_op_registrar.cpp
    ${OGR_CURRENT_SOURCE_DIR}/swq_parser.cpp
    ${OGR_CURRENT_SOURCE_DIR}/swq_select.cpp 
)

source_group("Header Files\\ogr" FILES ${OGR_HHEADERS})
set(GDAL_HHEADERS ${GDAL_HHEADERS} ${OGR_HHEADERS} )
source_group("Source Files\\ogr" FILES ${OGR_CSOURCES})
set(GDAL_CSOURCES ${GDAL_CSOURCES} ${OGR_CSOURCES} )

include(common)

add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts" "ogr\\ogrsf_frmts")
add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/generic" "ogr\\ogrsf_frmts\\generic")

if(OGR_MEM)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/mem" "ogr\\ogrsf_frmts\\mem")
    add_definitions(-DMEM_ENABLED)
endif(OGR_MEM)

if(OGR_VRT)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/vrt" "ogr\\ogrsf_frmts\\vrt")
    add_definitions(-DVRT_ENABLED)
endif(OGR_VRT)

if(OGR_CSV)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/csv" "ogr\\ogrsf_frmts\\csv")
    add_definitions(-DCSV_ENABLED)
endif(OGR_CSV)

if(OGR_DXF)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/dxf" "ogr\\ogrsf_frmts\\dxf")
    add_definitions(-DDXF_ENABLED)
endif(OGR_DXF)

if(OGR_SHP)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/shape" "ogr\\ogrsf_frmts\\shp")
    if(MSVC)
       add_definitions(-DSHAPELIB_DLLEXPORT) 
    endif(MSVC)
    add_definitions(-DSHAPE_ENABLED)
endif(OGR_SHP)

if(OGR_PG)
    find_package(POSTGRES REQUIRED)
    if(POSTGRES_FOUND)
        include_directories(${POSTGRES_INCLUDE_DIR})
        add_definitions(-DHAVE_PG)
    endif(POSTGRES_FOUND)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/pg" "ogr\\ogrsf_frmts\\pg")
    add_definitions(-DPG_ENABLED)   
endif(OGR_PG)

if(OGR_GML)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/gml" "ogr\\ogrsf_frmts\\gml")
    add_definitions(-DGML_ENABLED)
endif(OGR_GML)

if(OGR_TAB)
    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/mitab" "ogr\\ogrsf_frmts\\mitab")
    add_definitions(-DTAB_ENABLED)
endif(OGR_TAB)

if(OGR_LIBKML)
    find_package(Boost REQUIRED)    #COMPONENTS system thread regex program
    if(Boost_FOUND)
        include_directories(${Boost_INCLUDE_DIRS})
        add_definitions(-DHAVE_BOOST)
    endif(Boost_FOUND)
    find_package(LIBKML REQUIRED)
    if(LIBKML_FOUND)
        include_directories(${LIBKML_INCLUDE_DIR})
        add_definitions(-DHAVE_LIBKML)
    endif(LIBKML_FOUND)

    add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/libkml" "ogr\\ogrsf_frmts\\libkml")
endif(OGR_LIBKML)

add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/kml" "ogr\\ogrsf_frmts\\kml") #need always because OGR_G_ExportToKML in OGRGeometry class
if(OGR_KML)
    #add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/kml" "ogr\\ogrsf_frmts\\kml")
    add_definitions(-DKML_ENABLED)
endif(OGR_KML)

add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/geojson" "ogr\\ogrsf_frmts\\geojson") #need always because OGR_G_ExportToJson in OGRGeometry class
include_directories(${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/geojson)
add_files_macro("${OGR_CURRENT_SOURCE_DIR}/ogrsf_frmts/geojson/jsonc" "ogr\\ogrsf_frmts\\geojson\\jsonc")
if(OGR_JSON)    
    add_definitions(-DGEOJSON_ENABLED)
endif(OGR_JSON)



  
  
  
